home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / c / EasygadgetsSou.lha / EasyGadgets / Menu.c_backup < prev    next >
Text File  |  1995-02-26  |  3KB  |  145 lines

  1. /*
  2.  *    File:                    Menu.c
  3.  *    Description:    A set of functions to manipulate menus.
  4.  *
  5.  *    (C) 1994, Ketil Hunn
  6.  *
  7.  */
  8.  
  9. #ifndef    MENUFUNCTIONS_C
  10. #define    MENUFUNCTIONS_C
  11.  
  12. __asm UBYTE *egFindMenuTitle(    register __a0 struct Menu *mymenu,
  13.                                                             register __d0 ULONG idcmp)
  14. {
  15.     register struct Menu            *menu;
  16.     register struct MenuItem    *item, *sub;
  17.     register BYTE                            found=FALSE;
  18.     UBYTE                                            *title=NULL;
  19.  
  20. #ifdef MYDEBUG_H
  21.     DebugOut("egFindMenuNum");
  22. #endif
  23.  
  24.     for(menu=mymenu; menu!=NULL & found==FALSE; menu=menu->NextMenu)
  25.     {
  26.         title=(UBYTE *)menu->MenuName;
  27.         for(item=menu->FirstItem; item!=NULL; item=item->NextItem)
  28.         {
  29.             for(sub=item->SubItem; sub!=NULL & found==FALSE; sub=sub->NextItem)
  30.                 if(GTMENUITEM_USERDATA(sub)==(APTR)idcmp)
  31.                     found=TRUE;
  32.             if(GTMENUITEM_USERDATA(item)==(APTR)idcmp)
  33.                 found=TRUE;
  34.         }
  35.     }
  36.     return title;
  37. }
  38.  
  39. __asm struct MenuItem *egFindMenuItem(register __a0 struct Menu *mymenu,
  40.                                                                             register __d0 ULONG idcmp)
  41. {
  42.     register struct Menu            *menu;
  43.     register struct MenuItem    *item, *sub;
  44.  
  45. #ifdef MYDEBUG_H
  46.     DebugOut("egFindMenuItem");
  47. #endif
  48.  
  49.     for(menu=mymenu; menu!=NULL; menu=menu->NextMenu)
  50.         for(item=menu->FirstItem; item!=NULL; item=item->NextItem)
  51.         {
  52.             for(sub=item->SubItem; sub!=NULL; sub=sub->NextItem)
  53.                 if(GTMENUITEM_USERDATA(sub)==(APTR)idcmp)
  54.                     return sub;
  55.             if(GTMENUITEM_USERDATA(item)==(APTR)idcmp)
  56.                 return item;
  57.         }
  58.     return NULL;
  59. }
  60.  
  61. __asm __saveds BOOL egIsMenuItemChecked(register __a0 struct Menu *menu,
  62.                                                                                 register __d0 ULONG idcmp)
  63. {
  64.     register struct MenuItem    *item=egFindMenuItem(menu, idcmp);
  65.  
  66. #ifdef MYDEBUG_H
  67.     DebugOut("egIsMenu_ItemChecked");
  68. #endif
  69.  
  70.     if(item)
  71.         if(ISBITSET(item->Flags, CHECKED))
  72.             return TRUE;
  73.     return FALSE;
  74. }
  75.  
  76. __asm __saveds void egCheckMenuItem(register __a0 struct Window    *window,
  77.                                                                         register __a1 struct Menu        *menu,
  78.                                                                         register __d0 ULONG                    idcmp,
  79.                                                                         register __d1 BOOL                    check)
  80. {
  81.     register struct MenuItem    *item=egFindMenuItem(menu, idcmp);
  82.  
  83. #ifdef MYDEBUG_H
  84.     DebugOut("egCheckMenuItem");
  85. #endif
  86.  
  87.     if(window!=NULL)
  88.         if(item)
  89.         {
  90.             ClearMenuStrip(window);
  91.             IFTRUESETBIT(check, item->Flags, CHECKED);
  92.             ResetMenuStrip(window, menu);
  93.         }
  94. }
  95.  
  96. __asm __saveds void egDisableMenuItem(register __a0 struct Window    *window,
  97.                                                                             register __a1 struct Menu        *menu,
  98.                                                                             register __d0 ULONG                    idcmp,
  99.                                                                             register __d1 BOOL                    flag)
  100. {
  101.     register struct MenuItem    *item=egFindMenuItem(menu, idcmp);
  102.  
  103. #ifdef MYDEBUG_H
  104.     DebugOut("egDisableMenuItem");
  105. #endif
  106.  
  107.     if(window!=NULL)
  108.         if(item)
  109.         {
  110.             ClearMenuStrip(window);
  111.             IFFALSESETBIT(flag, item->Flags, NM_ITEMDISABLED);
  112.             ResetMenuStrip(window, menu);
  113.         }
  114. }
  115.  
  116. __asm __saveds void egSetMenuItem(register __a0 struct NewMenu    *menuitem,
  117.                                                                     register __d0 UBYTE                        type,
  118.                                                                     register __a1 STRPTR                    label,
  119.                                                                     register __d1 UWORD                        flags,
  120.                                                                     register __d2 LONG                        exclude,
  121.                                                                     register __a2 APTR                        userdata)
  122. {
  123.     if(label==NM_BARLABEL)
  124.     {
  125.         menuitem->nm_Label    =label;
  126.         menuitem->nm_CommKey=NULL;
  127.     }
  128.     else if(*label!=' ' & *(label+1)=='\0')
  129.     {
  130.         menuitem->nm_Label    =label+2;
  131.         menuitem->nm_CommKey=label;
  132.     }
  133.     else
  134.     {
  135.         menuitem->nm_Label    =label;
  136.         menuitem->nm_CommKey=NULL;
  137.     }
  138.     menuitem->nm_Type                    =type;
  139.     menuitem->nm_Flags                =flags;
  140.     menuitem->nm_MutualExclude=exclude;
  141.     menuitem->nm_UserData            =userdata;
  142. }                    
  143.  
  144. #endif
  145.